<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal">
		<span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
	<h4 class="modal-title">Пользователи &rArr; {% if user.login %}Редактирование{% else %}Добавление{% endif %}</h4>
</div>
<div class="modal-body">
	<form role="form" id="formPermis" class="form-horizontal">

		<div class="form-group">
			<label for="login" class="col-md-3 control-label">Логин:</label>

			<div class="col-md-9">
				<input name="login" type="text" class="form-control" id="login" placeholder="логин" value="{{ user.login|escape }}"{% if user.login %} readonly="readonly"{% endif %}>
			</div>
		</div>

		<div class="form-group">
			<label for="newPassword" class="col-md-3 control-label">Новый пароль:</label>

			<div class="col-md-9">
				<input name="password" type="password" class="form-control" id="newPassword" placeholder="новый пароль" value="">
			</div>
		</div>

		<table class="table table-striped table-hover">
			<thead>
			<tr>
				<th>Название</th>
				<th>Обозначение</th>
				<th>Состояние</th>
			</tr>
			</thead>
			<tbody>
			{% for r in permis %}
				<tr>
					<td>{{ r.title }}</td>
					<td>{{ r.name }}</td>
					<td>
						<label><input type="checkbox" name="permis[{{ r.name|escape }}]" value="1" class="checkbox"{% if user.permis[r.name] %} checked="checked"{% endif %}></label>
					</td>
				</tr>
			{% endfor %}
			</tbody>
		</table>

		<div class="text-right">
			<button type="button" class="btn btn-default" data-dismiss="modal">
				<span class="glyphicon glyphicon-ban-circle"></span> Назад
			</button>
			<button type="submit" class="btn btn-primary">
				{% if user.login %}
					<span class="glyphicon glyphicon-ok"></span> Применить
				{% else %}
					<span class="glyphicon glyphicon-plus-sign"></span> Добавить
				{% endif %}
			</button>
		</div>
	</form>
</div>
<script type="text/javascript">
	$(function () {
		$('#formPermis').ajaxForm({
			type: 'POST',
			dataType: 'json',
			url: '/admin/users/save',
			success: function (d) {
				window.location.reload();
			}
		})
	});
</script>
